import { useFloatPanel } from "@/hooks/index.js";
import LoadingPage from "@/views/exception/LoadingPage.vue";

const { floatPanel } = useFloatPanel();

export function createRouterGuards(router) {
    router.beforeEach((to, from, next) => {
        if (!to || !to.name) return next();
        if (needLoading(to)) displayLoadingPage();
        return next();
    });
    router.afterEach(() => {
        floatPanel.value = undefined;
    });
}

function needLoading(to) {
    return true;
}

function displayLoadingPage() {
    floatPanel.value = undefined;
    floatPanel.value = LoadingPage;
}
